package edu.sysu.demo.petstore.dog.web.rest;

import edu.sysu.demo.petstore.dog.key.KeyManagementException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.hateoas.VndErrors;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author lijinting01
 */
@Slf4j
@RestControllerAdvice
public class ServerErrorController {

  @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
  @ExceptionHandler(Exception.class)
  public VndErrors handle(Exception exception) {
    log.error("Unknown Error Happened:", exception);
    return new VndErrors("Unknown Error happened", exception.getMessage());
  }


  @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
  @ExceptionHandler(KeyManagementException.class)
  public VndErrors handle(KeyManagementException exception) {
    log.error("Key Management Error Happened:", exception);
    return new VndErrors("Key Management Error Happened:", exception.getMessage());
  }

}
